package com.smart.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.smart.model.domain.ManageUserRegistrationDO;
import com.smart.model.request.ManageUserRegistrationRequest;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * @author zhanghong
 */
@Repository
public interface ManageUserRegistrationMapper extends BaseMapper<ManageUserRegistrationDO> {
    ManageUserRegistrationDO selectById(Long id);

    List<ManageUserRegistrationDO> selectList(ManageUserRegistrationDO manageUserRegistration);

    int insertManageUserRegistration(ManageUserRegistrationDO manageUserRegistration);

    int batchInsertManageUserRegistration(List<ManageUserRegistrationDO> manageUserRegistrationDOList);

    int updateManageUserRegistration(ManageUserRegistrationDO manageUserRegistration);

    int deleteById(Long id);

    int deleteByIds(String[] ids);

    @Select({"<script>", "   select count(1) from manage_user_registration", "   <where>", "       deleted=0", "       <if test=\"1==0\">and id=#{param.id}</if>", "   </where>", "</script>"})
    long pageCount(@Param("param") ManageUserRegistrationRequest param);

    @Select({"<script>", "   select * from manage_user_registration", "   <where>", "       deleted=0", "       <if test=\"1==0\">and id=#{param.id}</if>", "   </where>", "   order by create_time desc limit #{limit} offset #{offset}", "</script>"})
    List<ManageUserRegistrationDO> pageQuery(@Param("param") ManageUserRegistrationRequest param, @Param("limit") int limit, @Param("offset") long offset);

    ManageUserRegistrationDO selectByIdCardAndProjectId(@Param("idCard") String idCard, @Param("projectId") Long projectId, @Param("leaveOrNot") Integer leaveOrNot);

    List<ManageUserRegistrationDO> pageQueryByRequest(ManageUserRegistrationRequest request);

    List<ManageUserRegistrationDO> selectByName(@Param("userName") String userName, @Param("projectId") Long projectId);

    List<Map<String, Object>> selectProjectPerson();

    Integer selectEightWeeklyData(@Param("leaveOrNot") int leaveOrNot, @Param("projectId") Long projectId, @Param("startDate") String startDate, @Param("endDate") String endDate);

    List<String> selectEightWeeklyDataByProjectId(@Param("projectId") Long projectId);

    Date getLastDate(Long projectId);

    Integer selectEightWeeklyDataByProjectIds(@Param("leaveOrNot") int leaveOrNot, @Param("list") List<Long> projectIds, @Param("startDate") String startDate, @Param("endDate") String endDate);

    Date getLastDateByProjectids(@Param("list") List<Long> projectIds);

    Integer countProject(Long projectId);

    List<ManageUserRegistrationDO> pageQueryManageByRequest(ManageUserRegistrationRequest request);

    List<ManageUserRegistrationDO> supervisePageLists(ManageUserRegistrationRequest request);

    List<String> selectCountPerson(Long projectId);

    Integer selectPerson(@Param("leaveOrNot") int leaveOrNot, @Param("projectId") Long projectId, @Param("startDate") String startDate, @Param("endDate") String endDate);

    Integer selectInoculateNumber(@Param("projectId") Long projectId, @Param("startDate") String startDate, @Param("endDate") String endDate);

    ManageUserRegistrationDO selectByProjectIdAndIdCard(@Param("projectId") Long projectId, @Param("idCard") String idCard);

    List<ManageUserRegistrationDO> selectByProjectIdAndIdCard2(@Param("projectId") Long projectId, @Param("idCard") String idCard);

    List<Map<String, Long>> selectAllNotLeavePerson();

    ManageUserRegistrationDO selectByIdCard(String idCard);

    Integer selectProjectPersonCount(Long id);

    List<ManageUserRegistrationDO> listAll(Long projectId);

    Integer selectLeaveOrNotByIdCards(@Param("idCards") List<String> idCards, @Param("projectId") Long projectId);

    Integer selectByParames(@Param("projectId") Long projectId, @Param("startTime") Date startTime, @Param("endTime") Date endTime);

    Integer selectOutCountByTime(@Param("startTime") Date startTime, @Param("endTime") Date endTime, @Param("projectId") Long projectId);

    List<String> selectPersonIdCards(@Param("projectId") Long projectId);

    Date selectLastUpdateTime(@Param("projectId") Long projectId);

    List<Long> selectInPersonProject();
    Integer selectInPersonProjectCount();

    List<Long> selectByTime(@Param("startTime") Date startTime, @Param("endTime") Date endTime, @Param("projectId") Long projectId);

    Integer selectByTime2(@Param("startTime") Date startTime, @Param("endTime") Date endTime, @Param("projectId") Long projectId);

    Integer selectOutByTime(@Param("startTime") Date startTime, @Param("endTime") Date endTime, @Param("projectId") Long projectId);

    List<String> selectInPersonIdcard();
    Integer selectInPersonIdcardCount();

    Integer countProjectCondition(@Param("startTime") Date startTime, @Param("endTime") Date endTime);

    Integer countPersonNum(@Param("projectId") Long projectId, @Param("startTime") Date startTime, @Param("endTime") Date endTime, @Param("leaveOrNot") Integer leaveOrNot);

    /**
     * 统计在监项目在场人数
     * @return
     */
    Integer countOnlineProjectPersonCount();

}
